home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nibble Magazine
/
nib15.dsk
/
TEXT EDITOR.bas
< prev
next >
Wrap
BASIC Source File
|
2023-02-26
|
8KB
|
395 lines
10 REM **********************
11 REM * TEXT EDITOR *
12 REM * BY PAUL M. HYMAN *
13 REM * COPYRIGHT (C) 1983 *
14 REM * BY MICROSPARC, INC *
15 REM * LINCOLN, MA. 01773 *
16 REM **********************
20 D$ = CHR$(4):ML = 1000
30 DIM L$(ML)
40 DIM FL%(ML)
50 DIM BL%(ML)
60 AVPTR = 0
70 IUPTR = 0
80 LL = 0
90 D$ = CHR$(4)
100 PRINT D$;"BLOAD STRINGIN"
110 INPUT "ENTER FILE NAME (RETURN IF NONE) ";FF$
120 IF FF$ < >"" GOTO 140
130 GOTO 310
140 ONERR GOTO 280
150 PRINT D$;"OPEN ";FF$
160 PRINT D$;"READ ";FF$
170 LL = LL +1
180 CALL 768,A$
190 L$(LL) = A$
200 IF LL >1 GOTO 220
210 GOTO 250
220 FL%(LL -1) = LL
230 BL%(LL) = LL -1
240 GOTO 260
250 IUPTR = 1
260 PRINT L$(LL)
270 GOTO 170
280 POKE 216,0
290 PRINT D$
300 CL = 1
310 HOME
320 GOSUB 3390
330 PRINT
340 INPUT "ENTER COMMAND ";C$
350 LC = LEN(C$)
360 IF LC >1 THEN GOTO 380
370 GOTO 460
380 N$ = RIGHT$(C$,LC -1)
390 N = VAL(N$)
400 C$ = LEFT$(C$,1)
410 IF N < = 0 GOTO 430
420 GOTO 450
430 PRINT "INVALID NUMBER"
440 GOTO 330
450 GOTO 470
460 N = 1
470 IF C$ = "Q" THEN GOTO 490
480 GOTO 560
490 IF SV = 0 GOTO 510
500 GOTO 540
510 PRINT "CHANGES NOT SAVED"
520 SV = 1
530 GOTO 550
540 END
550 GOTO 3240
560 IF C$ = "F" GOTO 580
570 GOTO 740
580 INPUT "STRING TO SEARCH FOR-";SF$
590 I = CL
600 PRINT ".";
610 GOSUB 3760
620 IF LM < >0 GOTO 660
630 I = FL%(I)
640 IF I = 0 GOTO 660
650 GOTO 600
660 PRINT
670 IF LM < >0 GOTO 690
680 GOTO 720
690 CL = I
700 GOSUB 3390
710 GOTO 730
720 PRINT "STRING NOT FOUND"
730 GOTO 3240
740 IF C$ = "X" GOTO 760
750 GOTO 1080
760 PRINT "STRING EXCHANGE"
770 INPUT "ENTER STRING TO SEARCH FOR:";SF$
780 INPUT "ENTER REPLACEMENT STRING:";RS$
790 I = CL
800 NT = 0
810 NT = NT +1
820 PRINT ".";
830 GOSUB 3760
840 IF LM < >0 GOTO 880
850 I = FL%(I)
860 IF I = 0 OR NT = N GOTO 880
870 GOTO 810
880 PRINT
890 IF LM < >0 GOTO 910
900 GOTO 1060
910 CL = I
920 IF LM >1 GOTO 940
930 GOTO 960
940 LF$ = LEFT$(L$(CL),LM -1)
950 GOTO 970
960 LF$ = ""
970 LR = LEN(L$(CL)) -LM - LEN(SF$) +1
980 IF LR >0 GOTO 1000
990 GOTO 1020
1000 LR$ = RIGHT$(L$(CL),LR)
1010 GOTO 1030
1020 LR$ = ""
1030 L$(CL) = LF$ +RS$ +LR$
1040 GOSUB 3390
1050 GOTO 1070
1060 PRINT "STRING NOT FOUND"
1070 GOTO 3240
1080 IF C$ = "P" GOTO 1100
1090 GOTO 1200
1100 I = 0
1110 L = CL
1120 IF I <N AND L < >0 GOTO 1140
1130 GOTO 1180
1140 PB$(I) = L$(L)
1150 L = FL%(L)
1160 I = I +1
1170 GOTO 1120
1180 NP = I
1190 GOTO 3240
1200 IF C$ = "M" GOTO 1220
1210 GOTO 1380
1220 SV = 0
1230 PRINT NP;" LINES IN PICK BUFFER"
1240 IF NP >0 GOTO 1260
1250 GOTO 1350
1260 FOR I = 0 TO NP -1
1270 GOSUB 3250
1280 L$(K) = PB$(I)
1290 BL%(K) = CL
1300 FL%(K) = FL%(CL)
1310 FL%(CL) = K
1320 CL = K
1330 NEXT
1340 GOTO 1360
1350 PRINT "NOTHING IN PICK BUFFER"
1360 GOSUB 3390
1370 GOTO 3240
1380 IF C$ = "L" GOTO 1400
1390 GOTO 1420
1400 GOSUB 3390
1410 GOTO 3240
1420 IF C$ = "" OR C$ = "+" GOTO 1440
1430 GOTO 1550
1440 FOR I = 1 TO N
1450 IF FL%(CL) < >0 GOTO 1470
1460 GOTO 1480
1470 CL = FL%(CL)
1480 NEXT
1490 IF N = 1 GOTO 1510
1500 GOTO 1530
1510 PRINT L$(CL)
1520 GOTO 1540
1530 GOSUB 3390
1540 GOTO 3240
1550 IF C$ = "-" GOTO 1570
1560 GOTO 1680
1570 FOR I = 1 TO N
1580 IF BL%(CL) < >0 GOTO 1600
1590 GOTO 1610
1600 CL = BL%(CL)
1610 NEXT
1620 IF N = 1 GOTO 1640
1630 GOTO 1660
1640 PRINT L$(CL)
1650 GOTO 1670
1660 GOSUB 3390
1670 GOTO 3240
1680 IF C$ = "R" GOTO 1700
1690 GOTO 1750
1700 SV = 0
1710 CALL 768,A$
1720 L$(CL) = A$
1730 GOSUB 3390
1740 GOTO 3240
1750 IF C$ = "I" GOTO 1770
1760 GOTO 1920
1770 SV = 0
1780 CALL 768,A$
1790 IF A$ = "" GOTO 1900
1800 GOSUB 3250
1810 L$(K) = A$
1820 IF CL < >0 GOTO 1840
1830 GOTO 1880
1840 BL%(K) = CL
1850 FL%(K) = FL%(CL)
1860 BL%(FL%(CL)) = K
1870 FL%(CL) = K
1880 CL = K
1890 GOTO 1780
1900 GOSUB 3390
1910 GOTO 3240
1920 IF C$ = "B" GOTO 1940
1930 GOTO 2100
1940 SV = 0
1950 CALL 768,A$
1960 IF A$ = "" GOTO 2080
1970 GOSUB 3250
1980 L$(K) = A$
1990 FL%(K) = CL
2000 BL%(K) = BL%(CL)
2010 IF BL%(CL) = 0 GOTO 2030
2020 GOTO 2050
2030 IUPTR = K
2040 GOTO 2060
2050 FL%(BL%(CL)) = K
2060 BL%(CL) = K
2070 GOTO 1950
2080 GOSUB 3390
2090 GOTO 3240
2100 IF C$ = "D" GOTO 2120
2110 GOTO 2460
2120 SV = 0
2130 PRINT "DELETE ";N;" LINE(S)"
2140 I = 0
2150 NP = 0
2160 IF I <N GOTO 2180
2170 GOTO 2400
2180 PB$(I) = L$(CL)
2190 Z = CL
2200 PRINT PB$(I)
2210 IF FL%(CL) = 0 GOTO 2230
2220 GOTO 2300
2230 CL = BL%(CL)
2240 FL%(CL) = 0
2250 FL%(Z) = AVPTR
2260 AVPTR = Z
2270 PRINT "END OF BUFFER"
2280 GOTO 2400
2290 GOTO 2350
2300 CL = FL%(CL)
2310 BL%(CL) = BL%(Z)
2320 FL%(BL%(Z)) = CL
2330 FL%(Z) = AVPTR
2340 AVPTR = Z
2350 IF BL%(CL) = 0 GOTO 2370
2360 GOTO 2380
2370 IUPTR = CL
2380 I = I +1
2390 GOTO 2160
2400 NP = N
2410 IF I <NP GOTO 2430
2420 GOTO 2440
2430 NP = I +1
2440 GOSUB 3390
2450 GOTO 3240
2460 IF C$ = "A" GOTO 2480
2470 GOTO 2700
2480 SV = 0
2490 RL$ = ""
2500 IF RL$ < >"R" AND RL$ < >"L" GOTO 2520
2510 GOTO 2540
2520 INPUT "ADJUST LINES RIGHT OR LEFT (R/L)? ";RL$
2530 GOTO 2500
2540 INPUT "HOW MANY SPACES? ";Q
2550 I = 0
2560 IF RL$ = "R" GOTO 2580
2570 GOTO 2610
2580 BB$ = " "
2590 L$(CL) = LEFT$(BB$,Q) +L$(CL)
2600 GOTO 2620
2610 L$(CL) = RIGHT$(L$(CL), LEN(L$(CL)) -Q)
2620 IF FL%(CL) < >0 GOTO 2640
2630 GOTO 2650
2640 CL = FL%(CL)
2650 I = I +1
2660 IF I = N OR FL%(CL) = 0 GOTO 2680
2670 GOTO 2560
2680 GOSUB 3390
2690 GOTO 3240
2700 IF C$ = "S" GOTO 2720
2710 GOTO 2840
2720 INPUT "FILE NAME-";F$
2730 PRINT D$;"OPEN";F$
2740 PRINT D$;"WRITE";F$
2750 I = IUPTR
2760 IF I < >0 GOTO 2780
2770 GOTO 2810
2780 PRINT L$(I)
2790 I = FL%(I)
2800 GOTO 2760
2810 PRINT D$;"CLOSE";F$
2820 SV = 1
2830 GOTO 3240
2840 IF C$ = "J" GOTO 2860
2850 GOTO 3020
2860 LC$ = ""
2870 IF LC$ < >"B" AND LC$ < >"E" GOTO 2890
2880 GOTO 2920
2890 INPUT "JUMP TO END OR BEGINNING?";C$
2900 LC$ = LEFT$(C$,1)
2910 GOTO 2870
2920 IF LC$ = "B" GOTO 2940
2930 GOTO 2960
2940 CL = IUPTR
2950 GOTO 3000
2960 IF FL%(CL) < >0 GOTO 2980
2970 GOTO 3000
2980 CL = FL%(CL)
2990 GOTO 2960
3000 GOSUB 3390
3010 GOTO 3240
3020 IF C$ = "V" GOTO 3040
3030 GOTO 3060
3040 PRINT "AVAILABLE MEM="; FRE(0)
3050 GOTO 3240
3060 PRINT "?"
3070 PRINT "LEGAL COMMANDS ARE:"
3080 PRINT "+ OR NULL: MOVE FORWARD"
3090 PRINT "-: MOVE BACKWARD"
3100 PRINT "I: INSERT LINES AFTER CURRENT LINE"
3110 PRINT "B: INSERT LINES BEFORE CURRENT LINE"
3120 PRINT "J: JUMP TO BEGINNING OR END OF FILE"
3130 PRINT "S: SAVE TO DISK"
3140 PRINT "Q: QUIT"
3150 PRINT "A: ADJUST LINES RIGHT OR LEFT"
3160 PRINT "D: DELETE LINES"
3170 PRINT "P: PICK LINES (TO USE WITH M COMMAND)"
3180 PRINT "M: MERGE IN PICKED OR DELETED LINES"
3190 PRINT "R: REPLACE CURRENT LINE"
3200 PRINT "F: FIND LINE CONTAINING SPECIFIED STRING"
3210 PRINT "X: EXCHANGE STRING"
3220 PRINT "V: PRINT AVAILABLE MEMORY"
3230 PRINT "L: LIST CURRENT LINE AND 10 BEFORE AND AFTER"
3240 GOTO 330
3250 IF IUPTR = 0 GOTO 3270
3260 GOTO 3310
3270 K = 1
3280 IUPTR = 1
3290 LL = 1
3300 GOTO 3380
3310 IF AVPTR = 0 GOTO 3330
3320 GOTO 3360
3330 LL = LL +1
3340 K = LL
3350 GOTO 3380
3360 K = AVPTR
3370 AVPTR = FL%(K)
3380 RETURN
3390 IF IUPTR = 0 GOTO 3410
3400 GOTO 3240
3410 RETURN
3420 HOME
3430 N = 10
3440 I = CL
3450 NT = 0
3460 NT = NT +1
3470 IF BL%(I) < >0 GOTO 3490
3480 GOTO 3500
3490 I = BL%(I)
3500 IF BL%(I) = 0 GOTO 3530
3510 IF NT = 10 GOTO 3530
3520 GOTO 3460
3530 FD = I
3540 NT = 0
3550 I = CL
3560 NT = NT +1
3570 IF FL%(I) < >0 GOTO 3590
3580 GOTO 3600
3590 I = FL%(I)
3600 IF FL%(I) = 0 GOTO 3630
3610 IF NT = 10 GOTO 3630
3620 GOTO 3560
3630 LD = I
3640 I = FD
3650 IF I = CL GOTO 3670
3660 GOTO 3680
3670 INVERSE
3680 PRINT L$(I)
3690 IF I = CL GOTO 3710
3700 GOTO 3720
3710 NORMAL
3720 IF I = LD GOTO 3750
3730 I = FL%(I)
3740 GOTO 3650
3750 RETURN
3760 LS = LEN(SF$)
3770 LM = 1
3780 A$ = L$(I)
3790 LA = LEN(A$)
3800 IF LM < = LA -LS +1 GOTO 3820
3810 GOTO 3870
3820 IF MID$ (A$,LM,LS) = SF$ GOTO 3840
3830 GOTO 3850
3840 GOTO 3880
3850 LM = LM +1
3860 GOTO 3800
3870 LM = 0
3880 RETURN
3890 END